﻿// //  ********************************************************************************
// //  Copyright (C) 2016 Sebastian Kenter. All rights reserved.
// // 
// //  Name    : MultiServerEngine | ServerFramework | ClientTelegramHandler.cs
// //  Created : 2016 - 02 - 16 20:53
// //  Modified: 2016 - 02 - 20 12:33
// //  ********************************************************************************

using ExitGames.Logging;
using ServerFramework.Interfaces.Client;
using ServerFramework.Interfaces.Handler;
using ServerFramework.Interfaces.Telegram;
using TypeDefs;

namespace ServerFramework.Implementation.Handler
{
    /// <summary>
    ///     Class ClientTelegramHandler.
    /// </summary>
    public abstract class ClientTelegramHandler : ITelegramHandler<IClientPeer>
    {
        /// <summary>
        ///     A logger to log
        /// </summary>
        /// <value>The logger.</value>
        public ILogger Logger { get; }

        /// <summary>
        ///     The type of the telegram handler (request, response, event)
        /// </summary>
        /// <value>The type.</value>
        public abstract TelegramHandlerTypes HandlerType { get; }

        /// <summary>
        ///     The code of the telegram handler - mapped to the code of the telegram
        /// </summary>
        /// <value>The code.</value>
        public abstract byte Code { get; }

        /// <summary>
        ///     The sub-code of the telegram handler - mapped to the sub-code of the telegram
        /// </summary>
        /// <value>The sub code.</value>
        public abstract int? SubCode { get; }

        /// <summary>
        ///     Initializes a new instance of the <see cref="ClientTelegramHandler" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        protected ClientTelegramHandler(ILogger logger)
        {
            Logger = logger;
        }

        /// <summary>
        ///     This handles the telegram itself
        /// </summary>
        /// <param name="telegram">The telegram to be handled</param>
        /// <param name="clientPeer">The peer that received the telegram</param>
        /// <returns>true if handled, otherwise false</returns>
        /// TODO Edit XML Comment Template for HandleTelegram
        public abstract bool HandleTelegram(ITelegram telegram, IClientPeer clientPeer);
    }
}
